package com.jrx.anytxn.transaction.service.impl;

import com.jrx.anytxn.common.exception.TxnException;
import com.jrx.anytxn.common.uitl.DateUtils;
import com.jrx.anytxn.customer.entity.CmCustomerAddressInfo;
import com.jrx.anytxn.customer.entity.CmCustomerContactInfo;
import com.jrx.anytxn.customer.entity.CmCustomerExtInfo;
import com.jrx.anytxn.customer.entity.CmCustomerFirstLevel;
import com.jrx.anytxn.customer.entity.CmCustomerSecondLevel;
import com.jrx.anytxn.customer.mapper.ext.ExtCmCustomerAddressInfoMapper;
import com.jrx.anytxn.customer.mapper.ext.ExtCmCustomerContactInfoMapper;
import com.jrx.anytxn.customer.mapper.ext.ExtCmCustomerExtInfoMapper;
import com.jrx.anytxn.customer.service.ICustomerService;
import com.jrx.anytxn.param.entity.PrOrganizationTable;
import com.jrx.anytxn.param.service.system.IOrganizationTableService;
import com.jrx.anytxn.param.utils.BizTypeProducts;
import com.jrx.anytxn.transaction.constant.TransBizConstant;
import com.jrx.anytxn.transaction.entity.*;
import com.jrx.anytxn.transaction.mapper.ext.*;
import com.jrx.anytxn.transaction.service.ITlCollectionService;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * 催收相关处理实现类
 */
@Service
public class TlCollectionServiceImpl implements ITlCollectionService {

    private static final Logger logger = LoggerFactory.getLogger(TlCollectionServiceImpl.class);

    @Autowired
    private IOrganizationTableService organizationTableService;
    @Autowired
    private ICustomerService customerService;
    @Resource
    private ExtCmCustomerAddressInfoMapper extCmCustomerAddressInfoMapper;
    @Resource
    private ExtCmCustomerContactInfoMapper extCmCustomerContactInfoMapper;
    @Resource
    private ExtAmLoanAccountInfoMapper extAmLoanAccountInfoMapper;
    @Resource
    private ExtAmLoanMainInfoMapper extAmLoanMainInfoMapper;
    @Resource
    private ExtAmRepaymentPlanInfoMapper extAmRepaymentPlanInfoMapper;
    @Resource
    private ExtTlCollectionLoanListMapper extTlCollectionLoanListMapper;
    @Resource
    private ExtAmDelinquencyInfoMapper extAmDelinquencyInfoMapper;
    @Resource
    private ExtCmCustomerExtInfoMapper extCmCustomerExtInfoMapper;

    @Override
    public void createFile(List<TlCollectionLoanList> tlCollectionLoanLists, String filePath, String fileName,Integer collectionPoolSize) throws TxnException {
        logger.info("开始生成催收文件");
        //获取当前业务日期
        PrOrganizationTable org = organizationTableService.findByOrgIdForBatch(TransBizConstant.DEFAULT_ORG_ID);
        Date bussinessDate = org.getNextProcessingDate();
        String toDay = DateUtils.format(bussinessDate,"yyyyMMdd");
        String collrctionPath = filePath + org.getTenantId() + File.separator + toDay + File.separator;

        List<String> outList = Collections.synchronizedList(new ArrayList<String>());//出催订单列表
        buildFileMess(tlCollectionLoanLists,collectionPoolSize,TransBizConstant.COLLECTION_FILE_TYPE_CUSTOMER,outList,collrctionPath,fileName,toDay);//生成客户信息文件
        buildFileMess(tlCollectionLoanLists,collectionPoolSize,TransBizConstant.COLLECTION_FILE_TYPE_CUSTOMER_ADDRESS,outList,collrctionPath,fileName,toDay);//生成客户地址信息文件
        buildFileMess(tlCollectionLoanLists,collectionPoolSize,TransBizConstant.COLLECTION_FILE_TYPE_CUSTOMER_CONTACT,outList,collrctionPath,fileName,toDay);//生成客户联系人信息文件
        buildFileMess(tlCollectionLoanLists,collectionPoolSize,TransBizConstant.COLLECTION_FILE_TYPE_LOAN_MAIN,outList,collrctionPath,fileName,toDay);//生成订单信息文件
        buildFileMess(tlCollectionLoanLists,collectionPoolSize,TransBizConstant.COLLECTION_FILE_TYPE_REPAYMENT_PLAN,outList,collrctionPath,fileName,toDay);//生成还款计划信息文件

        logger.error("催收准备表删除出催的数据");
        if(CollectionUtils.isNotEmpty(outList)){
            extTlCollectionLoanListMapper.batchDeleteByLoanId(outList);
        }
    }

    private void buildFileMess(List<TlCollectionLoanList> tlCollectionLoanLists,Integer collectionPoolSize,
                               String fileType,List<String> outList,String collrctionPath,String fileName,String toDay){
        List<String> collectionFileList = Collections.synchronizedList(new ArrayList<String>());

        //多线程处理
        int size = tlCollectionLoanLists.size();
        int tl = size % collectionPoolSize == 0 ? size / collectionPoolSize : (size
                / collectionPoolSize + 1);
        ExecutorService fixedThreadPool = Executors.newFixedThreadPool(collectionPoolSize);
        List<Future<String>> futures = new ArrayList<>(collectionPoolSize);
        for (int i = 0; i < collectionPoolSize; i++) {
            int end = (i + 1) * tl;
            if(i * tl >= size){
                break;
            }
            List<TlCollectionLoanList> proList = tlCollectionLoanLists.subList(i * tl, Math.min(end, size));
            Callable<String> task = () -> {
                String message = "S";
                if(TransBizConstant.COLLECTION_FILE_TYPE_CUSTOMER.equals(fileType)){
                    createCustomerFileMessage(proList,collectionFileList);
                }else if(TransBizConstant.COLLECTION_FILE_TYPE_CUSTOMER_ADDRESS.equals(fileType)){
                    createCustAddFileMessage(proList,collectionFileList);
                }else if(TransBizConstant.COLLECTION_FILE_TYPE_CUSTOMER_CONTACT.equals(fileType)){
                    createCustomerContactFileMessage(proList,collectionFileList);
                }else if(TransBizConstant.COLLECTION_FILE_TYPE_LOAN_MAIN.equals(fileType)){
                    createLoanFileMessage(proList,collectionFileList,outList);
                }else if(TransBizConstant.COLLECTION_FILE_TYPE_REPAYMENT_PLAN.equals(fileType)){
                    createLoanPlanFileMessage(proList,collectionFileList);
                }
                return message;
            };
            futures.add(fixedThreadPool.submit(task));
        }
        //获取处理结果
        for (Future<String> future : futures) {
            try {
                future.get();
            } catch (Exception e) {
                logger.error("生成"+fileType+"处理异常 : " ,e);
            }
        }
        fixedThreadPool.shutdown();
        logger.error("开始生成"+fileType+"文件");
        generatingFile(collectionFileList,collrctionPath ,fileName,toDay,fileType);


    }

    //客户信息文件
    private void createCustomerFileMessage(List<TlCollectionLoanList> proList,List<String> custInfoList) throws TxnException{
        for(TlCollectionLoanList info : proList){
            //1 获取客户信息
            CmCustomerFirstLevel customerFirstLevel = customerService.getFirstLevelByCondition(
                    info.getCustomerId(),info.getOrganizationId(),info.getTenantId());
            CmCustomerSecondLevel customerSecondLevel = customerService.getSecondByChannelAndCustomerIdAndTensnId(info.getChannel(),info.getCustomerId(),info.getTenantId(), info.getChannel());
            // 修改客户客群
            List<CmCustomerExtInfo> cmCustomerExtInfos = extCmCustomerExtInfoMapper.queryCustomerExtInfos(info.getCustomerId(), info.getTenantId(), BizTypeProducts.getSymbolProductId(info.getProductId()));
            if (CollectionUtils.isNotEmpty(cmCustomerExtInfos)) {
                customerSecondLevel.setCustomerGroup(cmCustomerExtInfos.get(0).getCustomerGroup());
            }
            createCustomerFileMessage(customerFirstLevel,customerSecondLevel,custInfoList);
        }
    }

    //客户信息文件
    private void createCustAddFileMessage(List<TlCollectionLoanList> proList,List<String> list) throws TxnException{
        for(TlCollectionLoanList info : proList){
            List<CmCustomerAddressInfo> addList = extCmCustomerAddressInfoMapper.selectByCustomerIdAndTenantId(
                    info.getCustomerId(),info.getTenantId());
            if(CollectionUtils.isNotEmpty(addList)){
                createCustomerAddressMessage(addList ,list);
            }
        }
    }

    //客户联系人信息
    private void createCustomerContactFileMessage(List<TlCollectionLoanList> proList,List<String> list) throws TxnException{
        for(TlCollectionLoanList info : proList){
            List<CmCustomerContactInfo> conttactList = extCmCustomerContactInfoMapper.selectByTenantIdAndCustomerId(
                    info.getTenantId(), info.getCustomerId());
            if(CollectionUtils.isNotEmpty(conttactList)){
                createCustomerContactMessage(conttactList ,list);
            }
        }
    }

    //订单信息
    private void createLoanFileMessage(List<TlCollectionLoanList> proList,List<String> list,List<String> outList) throws TxnException{
        for(TlCollectionLoanList info : proList){
            //4 获取订单，订单账户
            AmLoanMainInfo mianinfo = extAmLoanMainInfoMapper.selectByLoanId(
                    info.getLoanId(),info.getCustomerId(),info.getTenantId(),info.getChannel());
            AmLoanAccountInfo accountInfo = extAmLoanAccountInfoMapper.selectByLoanId(
                    info.getLoanId(),info.getCustomerId(),info.getTenantId());
            createLoanMessage(mianinfo,accountInfo ,list);
            //判断是否需要出催
            if(!TransBizConstant.ACCOUNT_STATUS_2.equals(accountInfo.getAccountStatus())){
                outList.add(accountInfo.getLoanId());
            }
        }
    }

    //还款计划
    private void createLoanPlanFileMessage(List<TlCollectionLoanList> proList,List<String> list) throws TxnException{
        for(TlCollectionLoanList info : proList){
            //4 获取还款计划
            List<AmRepaymentPlanInfo> planInfoList = extAmRepaymentPlanInfoMapper.selectByLoanId(
                    info.getLoanId(),info.getCustomerId(),info.getTenantId()
            );
            createPlanMessage(planInfoList,list);
        }
    }

    private void createCustomerFileMessage(CmCustomerFirstLevel customerFirstLevel,CmCustomerSecondLevel customerSecondLevel,List<String> custInfoList){
        StringBuffer sb = new StringBuffer();
        sb.append(customerFirstLevel.getTenantId() + TransBizConstant.separator);
        sb.append(customerFirstLevel.getCustomerId() + TransBizConstant.separator);
        sb.append(customerFirstLevel.getOrganizationId() + TransBizConstant.separator);
        sb.append(customerFirstLevel.getChineseName() + TransBizConstant.separator);
        sb.append(customerFirstLevel.getEnglishName() + TransBizConstant.separator);
        sb.append(customerFirstLevel.getCustomerStatus() + TransBizConstant.separator);
        sb.append(customerFirstLevel.getIdType() + TransBizConstant.separator);
        sb.append(customerFirstLevel.getIdNumber() + TransBizConstant.separator);
        sb.append(customerFirstLevel.getIdIssueAgent() + TransBizConstant.separator);
        sb.append(customerFirstLevel.getIdEffectiveDate() + TransBizConstant.separator);
        sb.append(customerFirstLevel.getIdExpireDate() + TransBizConstant.separator);
        sb.append(customerFirstLevel.getEcifId() + TransBizConstant.separator);
        String birthDate = customerFirstLevel.getBirthDate() == null ? null: DateUtils.formatDate(customerFirstLevel.getBirthDate());
        sb.append(birthDate + TransBizConstant.separator);
        sb.append(customerFirstLevel.getNationality() + TransBizConstant.separator);
        sb.append(customerFirstLevel.getRace() + TransBizConstant.separator);
        sb.append(customerFirstLevel.getSex() + TransBizConstant.separator);
        sb.append(customerSecondLevel.getChannel() + TransBizConstant.separator);
        sb.append(customerSecondLevel.getUserId() + TransBizConstant.separator);
        sb.append(customerSecondLevel.getCustomerType() + TransBizConstant.separator);
        sb.append(customerSecondLevel.getCustomerGroup() + TransBizConstant.separator);
        sb.append(customerSecondLevel.getMobile() + TransBizConstant.separator);
        sb.append(customerSecondLevel.getHomePhone() + TransBizConstant.separator);
        sb.append(customerSecondLevel.getCompanyName() + TransBizConstant.separator);
        sb.append(customerSecondLevel.getCompanyAttribute() + TransBizConstant.separator);
        sb.append(customerSecondLevel.getCompanyPhone() + TransBizConstant.separator);
        sb.append(customerSecondLevel.getMaritalStatus() + TransBizConstant.separator);
        sb.append(customerSecondLevel.getEducation() + TransBizConstant.separator);
        sb.append(customerSecondLevel.getStatementDd() + TransBizConstant.separator);
        sb.append(customerSecondLevel.getPaymentDd());
        custInfoList.add(sb.toString());
    }

    private void createCustomerAddressMessage(List<CmCustomerAddressInfo> addList,List<String> custAddList){
        for(CmCustomerAddressInfo addressInfo : addList){
            StringBuffer sb = new StringBuffer();
            sb.append(addressInfo.getTenantId() + TransBizConstant.separator);
            sb.append(addressInfo.getCustomerId() + TransBizConstant.separator);
            sb.append(addressInfo.getOrganizationId() + TransBizConstant.separator);
            sb.append(addressInfo.getAddressType() + TransBizConstant.separator);
            sb.append(addressInfo.getAddress() + TransBizConstant.separator);
            sb.append(addressInfo.getDistrict() + TransBizConstant.separator);
            sb.append(addressInfo.getCity() + TransBizConstant.separator);
            sb.append(addressInfo.getProvince() + TransBizConstant.separator);
            sb.append(addressInfo.getZipcode() + TransBizConstant.separator);
            sb.append(addressInfo.getChannel());
            custAddList.add(sb.toString());
        }
    }

    private void createCustomerContactMessage(List<CmCustomerContactInfo> conttactList,List<String> custConList){
        for(CmCustomerContactInfo Info : conttactList){
            StringBuffer sb = new StringBuffer();
            sb.append(Info.getTenantId() + TransBizConstant.separator);
            sb.append(Info.getCustomerId() + TransBizConstant.separator);
            sb.append(Info.getOrganizationId() + TransBizConstant.separator);
            sb.append(Info.getChannel() + TransBizConstant.separator);
            sb.append(Info.getChineseName() + TransBizConstant.separator);
            sb.append(Info.getEnglishName() + TransBizConstant.separator);
            sb.append(Info.getIdNumber() + TransBizConstant.separator);
            sb.append(Info.getIdType() + TransBizConstant.separator);
            sb.append(Info.getIdIssueAgent() + TransBizConstant.separator);
            sb.append(Info.getIdEffectiveDate() + TransBizConstant.separator);
            sb.append(Info.getIdExpireDate()+ TransBizConstant.separator);
            sb.append(Info.getSex()+ TransBizConstant.separator);
            sb.append(Info.getRelationship()+ TransBizConstant.separator);
            sb.append(Info.getHomeAddress()+ TransBizConstant.separator);
            sb.append(Info.getMobile()+ TransBizConstant.separator);
            sb.append(Info.getHomePhone()+ TransBizConstant.separator);
            sb.append(Info.getOfficePhone()+ TransBizConstant.separator);
            sb.append(Info.getEmail()+ TransBizConstant.separator);
            sb.append(Info.getCompanyName()+ TransBizConstant.separator);
            sb.append(Info.getCompanyAddress()+ TransBizConstant.separator);
            sb.append(Info.getOccuption()+ TransBizConstant.separator);
            sb.append(Info.getIncome());
            custConList.add(sb.toString());
        }
    }

    private void createLoanMessage(AmLoanMainInfo mianinfo,AmLoanAccountInfo accountInfo,List<String> loanList){
        StringBuffer sb = new StringBuffer();
        sb.append(mianinfo.getTenantId() + TransBizConstant.separator);
        sb.append(mianinfo.getLoanId() + TransBizConstant.separator);
        sb.append(mianinfo.getOrganizationId() + TransBizConstant.separator);
        sb.append(mianinfo.getChannel() + TransBizConstant.separator);
        sb.append(mianinfo.getProductId() + TransBizConstant.separator);
        sb.append(mianinfo.getCustomerId() + TransBizConstant.separator);
        sb.append(mianinfo.getLoanAmount() + TransBizConstant.separator);
        sb.append(mianinfo.getInterestRate() + TransBizConstant.separator);
        sb.append(mianinfo.getActualDailyRate() + TransBizConstant.separator);
        sb.append(mianinfo.getBillingCycle() + TransBizConstant.separator);
        sb.append(mianinfo.getPaymentDateDd() + TransBizConstant.separator);
        String interestStartDate = mianinfo.getInterestStartDate() == null ? null : DateUtils.formatDate(mianinfo.getInterestStartDate());
        sb.append(interestStartDate + TransBizConstant.separator);
        sb.append(mianinfo.getTotalTenor() + TransBizConstant.separator);
        String postingDate = mianinfo.getPostingDate() == null ? null : DateUtils.formatDate(mianinfo.getPostingDate());
        sb.append(postingDate + TransBizConstant.separator);
        sb.append(mianinfo.getContractId() + TransBizConstant.separator);
        sb.append(mianinfo.getContractNumber() + TransBizConstant.separator);
        sb.append(mianinfo.getCustomerAccountNumber() + TransBizConstant.separator);
        sb.append(mianinfo.getLoanUse() + TransBizConstant.separator);
        sb.append(mianinfo.getJointLoanFlag() + TransBizConstant.separator);
        String firstPaymentDate = mianinfo.getFirstPaymentDate() == null ? null : DateUtils.formatDate(mianinfo.getFirstPaymentDate());
        sb.append(firstPaymentDate + TransBizConstant.separator);
        String lastPaymentDate = mianinfo.getLastPaymentDate() == null ? null : DateUtils.formatDate(mianinfo.getLastPaymentDate());
        sb.append(lastPaymentDate + TransBizConstant.separator);
        sb.append(mianinfo.getTotalDays() + TransBizConstant.separator);
        sb.append(accountInfo.getAccountStatus() + TransBizConstant.separator);
        sb.append(accountInfo.getCurrBalance() + TransBizConstant.separator);
        sb.append(accountInfo.getPrincipalBalance() + TransBizConstant.separator);
        sb.append(accountInfo.getInterestBalance() + TransBizConstant.separator);
        sb.append(accountInfo.getPenaltyBalance().add(accountInfo.getAccruedPenalty()) + TransBizConstant.separator);
        sb.append(accountInfo.getCompoundBalance().add(accountInfo.getAccruedCompound()) + TransBizConstant.separator);
        sb.append(accountInfo.getFeeBalance() + TransBizConstant.separator);
        sb.append(accountInfo.getRemainPrincipal() + TransBizConstant.separator);
        sb.append(accountInfo.getCastTenor() + TransBizConstant.separator);
        sb.append(accountInfo.getPayedTenor() + TransBizConstant.separator);
        sb.append(accountInfo.getTotalCompensatoryTenor() + TransBizConstant.separator);
        sb.append(accountInfo.getContinueOverDueTenor() + TransBizConstant.separator);
        sb.append(accountInfo.getTotalOverDueTenor() + TransBizConstant.separator);
        //添加历史最大逾期天数
        int overDaysHis = countOverDaysHis(accountInfo);
        sb.append(overDaysHis + TransBizConstant.separator);
        sb.append(accountInfo.getAccountingPhase() + TransBizConstant.separator);
        sb.append(accountInfo.getDelqDays() + TransBizConstant.separator);
        String nextPaymentDate = accountInfo.getNextPaymentDate() == null ? null : DateUtils.formatDate(accountInfo.getNextPaymentDate());
        sb.append(nextPaymentDate + TransBizConstant.separator);
        sb.append(accountInfo.getCompelCollectionFlag());
        loanList.add(sb.toString());
    }

    private void createPlanMessage(List<AmRepaymentPlanInfo> planInfoList ,List<String> planList){
        for(AmRepaymentPlanInfo info : planInfoList){
            StringBuffer sb = new StringBuffer();
            sb.append(info.getLoanId() + TransBizConstant.separator);
            sb.append(info.getTenantId() + TransBizConstant.separator);
            sb.append(info.getBillingTenor() + TransBizConstant.separator);
            sb.append(info.getOrganizationId() + TransBizConstant.separator);
            sb.append(info.getChannel() + TransBizConstant.separator);
            sb.append(info.getPlanStatus() + TransBizConstant.separator);
            sb.append(info.getProductId() + TransBizConstant.separator);
            sb.append(info.getCustomerId()+ TransBizConstant.separator);
            sb.append(info.getTotalAmount()+ TransBizConstant.separator);
            sb.append(info.getPrincipalAmount()+ TransBizConstant.separator);
            sb.append(info.getInterestAmount()+ TransBizConstant.separator);
            sb.append(info.getFeeAmount()+ TransBizConstant.separator);
            sb.append(info.getRepayPrincipal()+ TransBizConstant.separator);
            sb.append(info.getRepayInterest()+ TransBizConstant.separator);
            sb.append(info.getRepayPenaltyInterest()+ TransBizConstant.separator);
            sb.append(info.getRepayFee()+ TransBizConstant.separator);
            sb.append(info.getRepayCompoundInterest()+ TransBizConstant.separator);
            String paymentDueDate = info.getPaymentDueDate() == null ? null : DateUtils.formatDate(info.getPaymentDueDate());
            sb.append(paymentDueDate+ TransBizConstant.separator);
            String transactionDate = info.getTransactionDate() == null ? null : DateUtils.formatDate(info.getTransactionDate());
            sb.append(transactionDate+ TransBizConstant.separator);
            String payoffDate = info.getPayoffDate() == null ? null : DateUtils.formatDate(info.getPayoffDate());
            sb.append(payoffDate+ TransBizConstant.separator);
            sb.append(info.getDelqDays()+ TransBizConstant.separator);
            sb.append(info.getOverDueAmount());
            planList.add(sb.toString());
        }
    }

    private void generatingFile(List<String> fileMessageList, String filePath ,String fileName,String toDay,String fileType){
        String collectionFileName = fileType+ "_" + toDay + "_" + fileName + ".txt";

        File path = new File(filePath);
        if (!path.exists() && !path.isDirectory()) {
            path.mkdirs();
        }
        File customerFile = new File(filePath + collectionFileName);
        if(TransBizConstant.COLLECTION_FILE_TYPE_REPAYMENT_PLAN.equals(fileType)||TransBizConstant.COLLECTION_FILE_TYPE_LOAN_MAIN.equals(fileType)){
            createFileByFileName(customerFile,fileMessageList,TransBizConstant.NO_FLAG);
        }else{
            createFileByFileName(customerFile,fileMessageList,TransBizConstant.YES_FLAG);
        }
    }

    private void createFileByFileName(File fileName,List<String> meaageList,String duplicate ){

        List<String> newList = new ArrayList<>();
        if(CollectionUtils.isNotEmpty(meaageList)){
            if(TransBizConstant.YES_FLAG.equals(duplicate)){
                for(String message : meaageList){
                    if(!newList.contains(message)){
                        newList.add(message);
                    }
                }
            }else{
                newList.addAll(meaageList);
            }
        }

        FileWriter fw = null;
        BufferedWriter writer = null;
        Integer i = 0;
        try {
            fw = new FileWriter(fileName);
            writer = new BufferedWriter(fw);
            for (String custMssage : newList) {
                i++;
                if(i == newList.size()){
                    writer.write(custMssage);
                }else{
                    writer.write(custMssage + "\r\n");
                }
                writer.flush();
            }
        } catch (IOException e) {
            logger.error("催收文件失败，失败信息：",e);
        } finally {
            try {
                writer.close();
                fw.close();
            } catch (IOException e) {
                logger.error("", e);
            }
        }
    }

    private int countOverDaysHis(AmLoanAccountInfo accountInfo){
        int overDays = 0;
        //查询延滞交易账户
        List<AmDelinquencyInfo> amDelinquencyInfoList = extAmDelinquencyInfoMapper.selectDelqInfoByLoanId(accountInfo.getLoanId(),accountInfo.getCustomerId(),
                accountInfo.getTenantId(),null);
        if(CollectionUtils.isEmpty(amDelinquencyInfoList)){
            return overDays;
        }
        for(AmDelinquencyInfo info : amDelinquencyInfoList){
            if(info.getDelqDays() > overDays){
                overDays = info.getDelqDays();
            }
        }
        return overDays;
    }

}
